package com.asktgapp.utils;

import android.app.Activity;
import android.text.TextUtils;


import com.asktgapp.R;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;

/**
 * Description:{}
 * time:2017/8/16
 * Create By ZhaoKai
 * Email: dczk@foxmail.com
 */

public class UmengShareUtils {

    /**
     * 社会化分享
     * @param activity
     * @param platform SHARE_MEDIA
     * @param title  title参数对新浪、人人、豆瓣不生效
     * @param text
     * @param targetUrl
     * @param umShareListener
     *
     *      值得注意的是，分享也应该重写
     *      onActivityResult()
     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     super.onActivityResult(requestCode, resultCode, data);
     UMShareAPI.get( this ).onActivityResult( requestCode, resultCode, data);
     }
     */

    public static void socialShare(Activity activity, SHARE_MEDIA platform, String title, String text, String targetUrl, String pic, UMShareListener umShareListener){
        UMWeb web = new UMWeb(targetUrl);
        web.setTitle(title);//标题
        web.setDescription(text);
        if(TextUtils.isEmpty(pic)){
            web.setThumb(new UMImage(activity, R.mipmap.logo));  //缩略图
            new ShareAction(activity).setPlatform(platform).setCallback(umShareListener)
                    .withMedia(web)//默认用logo//采用了直角的logo
                    .share();
        }else{
            web.setThumb(new UMImage(activity, pic));
            new ShareAction(activity).setPlatform(platform).setCallback(umShareListener)
                    .withMedia(web)//默认用logo
                    .share();
        }

    }
}
